package leetcode.tree;

/**
 * @author MaoLin Wang
 * @date 2020/2/1411:20
 */
public class TreeNode {
   public int val;
   public TreeNode left;
   public TreeNode right;

    public TreeNode(int x) {
        val = x;
    }
    public TreeNode(int x,TreeNode left,TreeNode right) {
        val = x;
        this.left=left;
        this.right=right;
    }

    @Override
    public String toString() {
        return "TreeNode{" +
                "val=" + val +
                ", left=" + left +
                ", right=" + right +
                '}';
    }
    public void preOrder(){
        System.out.println(this.val);
        if (left!=null){
            left.preOrder();
        }
        if (right!=null){
            right.preOrder();;
        }
    }
}
